import {
    observable,
    action
} from "mobx-miniprogram";
import {
    keyDept,
    keyTeam,
    keyUser
} from "../utils/util";

export const workOrderReviewIndexFilterStore = observable({
    //  建单人ID多选
    buildIdList: [],
    //  完成结束日期(yyyy-MM-dd)
    completeEndTime: '',
    //  完成开始日期(yyyy-MM-dd)
    completeStartTime: '',
    //  报修科室ID多选
    deptIdList: [],
    //  故障分类多选
    faultTypeList: '',
    //  处理科室ID多选
    makeDeptIdList: [],
    //  处理小组ID多选
    makeTeamIdList: [],
    //  处理人ID多选
    makeUserIdList: [],
    //  报修结束日期(yyyy-MM-dd)
    repairEndTime: '',
    //  报修开始日期(yyyy-MM-dd)
    repairStartTime: '',
    // 设置报修时间
    setRepairDate: action(function (date) {
        this.repairEndTime = date[1]
        this.repairStartTime = date[0]

    }),
    //设置完成时间
    setCompleteDate: action(function (date) {
        this.completeStartTime = date[0]
        this.completeEndTime = date[1]

    }),
    // 设置报修科室
    setDeptIdList: action(function (list) {
        this.deptIdList = list.map(item => item.value)
    }),
    // 设置故障分类
    setFaultTypeList: action(function (list) {
        console.log(list, 'setFaultTypeList');
        this.faultTypeList = list.map(item => item.value)
    }),
    // 设置建单人
    setBuildIdList: action(function (list) {
        this.buildIdList = list.map(item => item.userId)
    }),
    // 设置处理科室/小组/人
    setDepTeamUser: action(function (list) {
        console.log(list, 'setDepTeamUser');
        const depts = list.filter(item => item.key === keyDept)
        const teams = list.filter(item => item.key === keyTeam)
        const users = list.filter(item => item.key === keyUser)

        this.makeDeptIdList = depts.map(item => item.value)
        this.makeTeamIdList = teams.map(item => item.value)
        this.makeUserIdList = users.map(item => item.value)


    }),
    // 重置
    workOrderReviewIndexFilterStoreReset: action(function () {
        this.buildIdList = []
        this.completeEndTime = ''
        this.completeStartTime = ''
        this.deptIdList = []
        this.faultTypeList = ''
        this.makeDeptIdList = []
        this.makeTeamIdList = []
        this.makeUserIdList = []
        this.repairEndTime = ''
        this.repairStartTime = ''
    })


});